﻿using amuudp.package;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace amuudp.sender
{
    public class MessageSender : Sender
    {
        private int clientId;
        private byte[] messageBytes;

        public MessageSender(int clientId, string message, IPEndPoint iPEndPoint) : base(iPEndPoint, null)
        {
            this.clientId = clientId;
            messageBytes = Encoding.UTF8.GetBytes(message);
            createDataBytes();
        }

        private void createDataBytes()
        {
            data = new byte[16 + messageBytes.Length];
            byte[] clientIdBytes = BitConverter.GetBytes(clientId);
            byte[] typeBytes = BitConverter.GetBytes(PackageType.Message);
            Array.Copy(clientIdBytes, 0, data, 0, 4);
            Array.Copy(typeBytes, 0, data, 8, 4);
            Array.Copy(messageBytes, 0, data, 16, messageBytes.Length);
        }
    }

}
